//
//  HMStudentRenewdetails.m
//  优学荟管理系统
//
//  Created by 陈辉明 on 2017/12/11.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "HMStudentRenewdetails.h"
#import "HMRenewdetailsHeadView.h"
#import "HMRenewdetailsCell.h"
#import "HMRenewdetailsModel.h"

@interface HMStudentRenewdetails () <UITableViewDataSource,UITableViewDelegate>;

@property (weak, nonatomic) IBOutlet UITableView *tableView;
/** 头部视图 */
@property (nonatomic, strong) HMRenewdetailsHeadView *HeaderView;

/** 开始时间 */
@property (nonatomic, strong) NSString *BeginTimeStr;
/** 结束时间 */
@property (nonatomic, strong) NSString *EndTimeStr;

@property(nonatomic,strong) NSMutableArray *dataSource;


@end

@implementation HMStudentRenewdetails

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"缴费详情";
    self.BeginTimeStr = [NSString yearMonthDay];
    self.EndTimeStr = [NSString yearMonthDay];
    [self setUpTableView];
    [self setNetWork];
}


- (void)setUpTableView {
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"HMRenewdetailsCell" bundle:nil] forCellReuseIdentifier:@"HMRenewdetailsCellId"];
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 126;
//    self.tableView.rowHeight = 126;
    self.tableView.tableHeaderView = [UIView new];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HMRenewdetailsModel *model = self.dataSource[indexPath.row];
    HMRenewdetailsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HMRenewdetailsCellId" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = model;
    return cell;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    return self.HeaderView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 183;
}





#pragma mark - Get
-(HMRenewdetailsHeadView *)HeaderView {
    if (!_HeaderView) {
        
        _HeaderView = [HMRenewdetailsHeadView ConfigHeaderViewOfSureAction:^(NSString *BeginTimeStr, NSString *EndTimeStr, UIButton *SureBtn) {
            
            self.BeginTimeStr = BeginTimeStr;
            self.EndTimeStr = EndTimeStr;
            [self setNetWork];
        }];
    }
    return _HeaderView;
}


#pragma mark - 网络请求
- (void)setNetWork{
    
    
    //http://192.168.0.226:8080/StarShine/ys/yxhUser.do?action=getStuPayment&startTime=2017-10-01&endTime=2017-12-08
    
    NSString *url = [NSString stringWithFormat:@"yxhUser.do?action=getStuPayment&startTime=%@&endTime=%@",self.BeginTimeStr,self.EndTimeStr];
    NSLog(@"%@ %@",LLBaseURL(url),[AccountTool shareAccountTool].currentAccount.authCode);
    [SVProgressHUD setDefaultStyle:(SVProgressHUDStyleCustom)];
    [SVProgressHUD  setBackgroundColor:ColorRGB(4, 4, 4)];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD showWithStatus:LLLoading];
    
    [NetManager Get:LLBaseURL(url) Auth:YES Params:nil Success:^(id Obj) {
        [SVProgressHUD dismiss];
        if ([[Obj valueForKey:@"code"]integerValue] == 1000) {
            [self.dataSource removeAllObjects];
            NSDictionary *dict = [Obj valueForKey:@"t"];
            [self.dataSource addObject:[HMRenewdetailsModel HMRenewdetailsModelWithDict:dict]];
            [self.tableView reloadData];
        }
                
    } Fail:^(NSError *Error) {

        [SVProgressHUD dismiss];
    }];
    
}

-(NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray new];
    }
    return _dataSource;
}



@end
